@inherits VocaDb.Web.Code.HelperPage
@using System.Web.Mvc.Html;
@using HelperRes
@using VocaDb.Web.Code
@using VocaDb.Web.Helpers;
@using VocaDb.Model.DataContracts.Activityfeed;
@using VocaDb.Model.Domain
@using VocaDb.Model.Domain.Activityfeed;
@using VocaDb.Model.Service.Helpers

@helper EntryType(ActivityEntryForApiContract entry) {
	@EntryType(entry.EditEvent, entry.Entry.EntryType)
}

@helper EntryType(EntryEditEvent editEvent, EntryType entryType) {

	var tr = HelperRes.ActivityFeedHelperStrings.ResourceManager.GetString(editEvent.ToString() + entryType);

	if (!string.IsNullOrEmpty(tr)) {

		<span>@tr</span>

	} else {

		var entryTypeName = HelperRes.ActivityFeedHelperStrings.ResourceManager.GetString("Entry" + entryType);

		if (editEvent == EntryEditEvent.Created) {
			<span>@string.Format(HelperRes.ActivityFeedHelperStrings.CreatedNew, entryTypeName)</span>
		} else {
			<span>@string.Format(HelperRes.ActivityFeedHelperStrings.Updated, entryTypeName)</span>
		}

	}

}

@helper ActivityEntry(ActivityEntryForApiContract entry, bool showDetails = false) {
	var thumbUrl = entry.Entry.MainPicture != null ? UrlHelper.UpgradeToHttps(entry.Entry.MainPicture.GetSmallestThumb(VocaDb.Model.Domain.Images.ImageSize.TinyThumb)) : null;
	<div class="message activityEntry ui-tabs ui-widget ui-widget-content ui-corner-all">
		@if (entry.Author != null) {
			@UserHelpers.UserIconLink(entry.Author, userInfo: true)
		} else {
			@HelperRes.ActivityFeedHelperStrings.Someone
		}

		@EntryType(entry)

		<small class="pull-right extraInfo" title="@entry.CreateDate.ToUniversalTime().ToString("g") UTC">
			@TimeAgoStringBuilder.FormatTimeAgo(entry.CreateDate)
		</small>

		<div class="media">
			@if (!string.IsNullOrEmpty(thumbUrl)) {
				<a class="pull-left" href="@Url.EntryDetails(entry.Entry)" title="@entry.Entry.AdditionalNames">
					<img src="@thumbUrl" alt="thumb" class="media-object coverPicThumb" />
				</a>
			}
			<div class="media-body">
				<h4 class="media-heading">
					<a href="@Url.EntryDetails(entry.Entry)" title="@entry.Entry.AdditionalNames">
						<strong>@entry.Entry.Name</strong>
					</a>
				</h4>
				@if (!string.IsNullOrEmpty(entry.Entry.ArtistString)) {
					@entry.Entry.ArtistString
				}
			</div>
		</div>
	</div>
}

@helper ActivityEntryKnockout(string entryTypeNamesBinding, string activityFeedEventNamesBinding, string changedFieldNamesBinding, bool showDetails = false) {
	<div class="message activityEntry ui-tabs ui-widget ui-widget-content ui-corner-all">
		<span data-bind="with: $data.author">
			@UserHelpers.IconNameAndTypeLinkKnockout("$parents[1].resources.resources().userGroupNames")
		</span>
		<span data-bind="visible: !$data.author">@ActivityFeedHelperStrings.Someone</span>

		<span data-bind="text: @(activityFeedEventNamesBinding)($data)"></span>

		@if (showDetails) {
			<span data-bind="with: $data.archivedVersion">
				<span visible="{{ $data.changedFields && $data.changedFields.length }}">({{ @(changedFieldNamesBinding)($parent.entry, $data) }})</span>
				<span visible="{{ $data.notes }}">{{ '\"' + $data.notes + '\"' }}</span>
				
				<span visible="{{ $parent.entry.entryType !== 'Tag' && $parent.entry.entryType !== 'SongList' && $parent.entry.entryType !== 'ReleaseEvent' }}">
					(<a href="#" data-bind="attr: { href: '/' + $parent.entry.entryType + '/ViewVersion/' + id }">@ViewRes.MiscStrings.Details</a>)
				</span>
			</span>
		}

		<small class="pull-right extraInfo" data-bind="attr: { title: createDate }, timeAgo: createDate"></small>

		<div class="media">
			<a class="pull-left" visible="{{ entry.mainPicture && (entry.mainPicture.urlTinyThumb || entry.mainPicture.urlSmallThumb) }}" href="{{ $parent.getEntryUrl(entry) }}" title="{{ entry.additionalNames }}">
				<img attr.src="{{ entry.mainPicture ? (entry.mainPicture.urlTinyThumb || entry.mainPicture.urlSmallThumb) : '' }}" alt="thumb" class="media-object coverPicThumb" />
			</a>
			<div class="media-body">
				<h4 class="media-heading">
					<a href="{{ $parent.getEntryUrl(entry) }}" title="{{ entry.additionalNames }}">
						<strong>{{ entry.name }}</strong>
					</a>
					<span visible="{{ @(entryTypeNamesBinding)(entry) }}">({{ @(entryTypeNamesBinding)(entry) }})</span>
				</h4>

				<span visible="{{ entry.artistString }}">{{ entry.artistString }}</span>
			</div>
		</div>
	</div>
}
